package com.xc.controller;

import com.xc.dto.ResultDTO;
import com.xc.entity.CourseEntity;
import com.xc.entity.ShoppingEntity;
import com.xc.entity.WebShoppingEntity;
import com.xc.service.CourseService;
import com.xc.service.ShoppingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//restful 增加post，修改put，删除delete，查询get
@RestController
@RequestMapping("/xc/shopping")
@Api(tags = "购物车功能管理")
public class ShoppingController {
    @Autowired
    private ShoppingService shoppingService;

    @ApiOperation(value = "购物车功能增加", notes = "购物车功能增加接口的说明")
    @PostMapping()
    public ResultDTO add(WebShoppingEntity webShoppingEntity) {
        return shoppingService.add(webShoppingEntity);
    }

    @ApiOperation("购物车功能修改")
    @PutMapping()
    public ResultDTO update(WebShoppingEntity webShoppingEntity) {
        return shoppingService.update(webShoppingEntity);
    }

    @ApiOperation("根据id进行删除购物车功能数据")
    @DeleteMapping("/{id}")
    public ResultDTO delete(WebShoppingEntity webShoppingEntity) {
        return shoppingService.delete(webShoppingEntity);
    }

    @ApiOperation("查询所有购物车功能数据")
    @GetMapping()
    public ResultDTO findAll(WebShoppingEntity webShoppingEntity) {
        return shoppingService.findAll(webShoppingEntity);
    }

    @ApiOperation("根据课程id和用户名id查询是否已经添加了该课程")
    @GetMapping("/{courseId}/{userId}")
    public ResultDTO findByCourseIdAndUserId(WebShoppingEntity webShoppingEntity) {
        return shoppingService.findByCourseIdAndUserId(webShoppingEntity);
    }

    @ApiOperation("根据id查询购物车功能")
    @GetMapping("/{id}")
    public ResultDTO findById(WebShoppingEntity webShoppingEntity) {
        return shoppingService.findById(webShoppingEntity);
    }@ApiOperation("根据用户id查询当前用户购物车的课程")
    @GetMapping("/course/{userId}")
    public ResultDTO findByUserId(WebShoppingEntity webShoppingEntity) {
        return shoppingService.findByUserId(webShoppingEntity);
    }

    @ApiOperation("查询购物车功能总条数")
    @GetMapping("/count")
    public ResultDTO count(WebShoppingEntity webShoppingEntity) {
        return shoppingService.count(webShoppingEntity);
    }
}
